package descentFly.weaponts
{
	import away3d.containers.Scene3D;
	
	import descentFly.away3D4.chips.df_chipAway;
	import descentFly.away3D4.df_awaySpace;
	import descentFly.chips.df_chip;
	import descentFly.chips.df_weapont;
	
	import flash.geom.Matrix3D;
	import flash.geom.Vector3D;
	
	public class df_awayWeapont extends df_weapont {
		public function df_awayWeapont(a_chip:df_chip, a_options: Object) {
			super(a_chip, a_options);
		}
		
		protected function get scene(): Scene3D {
			return (Space as df_awaySpace).view.view.scene;
		}
		
		protected function get chipAway(): df_chipAway {
			return chip as df_chipAway;
		}
		
		public function startTransform(cannonIndex: int): Matrix3D {
			var offset: Vector3D = new Vector3D(options.offset[cannonIndex].x, options.offset[cannonIndex].y, options.offset[cannonIndex].z);
			var t: Matrix3D = chipAway.body.skin.transform.clone();
			t.prependTranslation(offset.x, offset.y, offset.z);
			return t;
		}
		
		public function get attachmentPoint(): Vector3D {
			var p: Vector3D = new Vector3D();
			var count: int = options.offset.length;
			for (var i: int=0; i<count; i++) {
				p.x -= options.offset[i].x;
				p.y -= options.offset[i].y;
				p.z -= options.offset[i].z;
			}
			
			p.x /= count;
			p.y /= count;
			p.z /= count;
			return p; 
		}
		
		public function get distance(): Number {
			return options.bullet.options.distance;
		}
	}
}